package com.jinxin.platform.cdacscontrolmgr.controller;

import com.jinxin.platform.base.api.annotation.APCOSApi;
import com.jinxin.platform.base.api.annotation.APCOSApiOperation;
import com.jinxin.platform.base.api.constant.APCOSApiConstans;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdacscontrolmgr.bean.CdyardmgrCarCategory;
import com.jinxin.platform.cdacscontrolmgr.common.SysOrgInfo;
import com.jinxin.platform.cdacscontrolmgr.rpc.CdacscontrolmgrRpc;
import com.jinxin.platform.cdacscontrolmgr.service.ICdacscontrolmgrCarCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-09-06
 * @Author: Lingnan
 **/
@APCOSApi(value = "车辆类型接口", developers = {"lingnan"}, description = "车辆类型接口")
@RestController
@RequestMapping("/cdacscontrolmgr/cdacscontrolmgrCarCategory")
@Slf4j
public class CdacscontrolmgrCarCategoryController {
    @Autowired
    private ICdacscontrolmgrCarCategoryService carCategoryService;
    @Autowired
    private CdacscontrolmgrRpc cdacscontrolmgrRpc;

    @APCOSApiOperation(value = "分页查询车辆类型", developers = {"lingnan"}, description = "分页查询车辆类型",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/list")
    public Map<String,Object> list(@RequestParam int page, @RequestParam int limit,String name){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("code",0);
        SysOrgInfo currentOrg = cdacscontrolmgrRpc.getCurrentOrg();
        if(currentOrg == null){
            resultMap.put("msg","获取当前组织信息失败");
            resultMap.put("data", null);
            return resultMap;
        }
        HashMap param = new HashMap();
        param.put("page", page);
        param.put("limit", limit);
        param.put("name", name);
        param.put("orgId", currentOrg.getOrgId());
        resultMap.put("count", carCategoryService.listPageCount(param));
        resultMap.put("data", carCategoryService.listPage(param));
        return resultMap;
    }

    @APCOSApiOperation(value = "保存或修改车辆类型", developers = {"lingnan"}, description = "保存或修改车辆类型",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @PostMapping("/saveOrUpdate")
    public JsonResult saveOrUpdate(@RequestBody CdyardmgrCarCategory record){
        return carCategoryService.saveOrUpdate(record);
    }

    @APCOSApiOperation(value = "删除车辆类型", developers = {"lingnan"}, description = "删除车辆类型",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/delete")
    public JsonResult delete(String id){
        return carCategoryService.delete(id);
    }

//    @APCOSApiOperation(value = "获取字典项", developers = {"lingnan"}, description = "获取字典项",
//            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
//    @GetMapping("/getDictItems")
//    public JsonResult getDictItems(String dictType){
//        if(StringUtils.isEmpty(dictType)){
//            return null;
//        }
//        return cdacscontrolmgrRpc.getDictItems(dictType);
//    }

    @APCOSApiOperation(value = "根据组织查询车辆类别", developers = {"lingnan"}, description = "根据组织查询车辆类别",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/listAll")
    public JsonResult listAll(){
        SysOrgInfo currentOrg = cdacscontrolmgrRpc.getCurrentOrg();
        if(currentOrg == null){
            return null;
        }
        HashMap param = new HashMap();
        param.put("orgId",currentOrg.getOrgId());
        return JsonResult.ok(carCategoryService.list(param));
    }

}
